<?php

namespace Analysis\Controller;

class CashController extends CommController
{
    public function index()
    {
        $settlement = M("settlement");

        $data = commpage($settlement, "set_status<200", "set_time desc", 12);
        $this->assign("data", $data);
        $this->display();
    }

    public function applyinfo($ssi)
    {
        $settlement = M("settlement");
        $disisbn = M("disisbn");
        $cash = M("cash");

        $info = $settlement->find($ssi);
        $this->assign("info", $info);
        //sale code
        if ($info['set_ssaid'] != 0) {
            $code = $disisbn->where("dis_ssaid=" . $info['set_ssaid'])->find();
            $this->assign("code", $code);
        }
        //bill history
        $info['set_ssaid'] == 0 ? $where["c_agent"] = $info['set_agent'] : $where["c_disid"] = $code['dis_id'];
        $where["c_month"] = $info["set_month"];
        $list = $cash->where($where)->select();
        $this->assign("list", $list);
        $this->display();
    }

    public function finrovl()
    {
        $settlement = M("settlement");

        $data = commpage($settlement, "set_status>=200", "set_time desc", 12);
        $this->assign("data", $data);
        $this->display();
    }

    public function checkinfo($ssi)
    {
        $settlement = M("settlement");

        $info = $settlement->find($ssi);
        $this->assign("info", $info);
        $this->display();
    }

    /**
    * 账务管理
    * @param type $sid
    */
    public function applyFi($sid)
    {
        $settlement = M("settlement");

        $settlement->create();
        if ($settlement->where("set_id=".$sid)->save()) {
            $this->success("处理成功");
        } else {
            $this->error("处理失败");
        }
    }

    public function report()
    {
        $saletype = M("saletype");

        $cat = $saletype->where("sat_status=1")->select();
        $this->assign("cat", $cat);
        $this->display();
    }

    public function reportGet()
    {
        $static = D("Static");
        $couponhis = M("couponhis");
        $order = M("order", "yub_", C("CONN_YYB"));

        $po = I("post.");
        $s = strtotime($po["timestart"]);
        $e = strtotime($po["timeend"]);
        $chart = $static->getInitialParam($s, $e, "ord_addtime");
        $po["order"] != "99" ? $where["ord_status"] = $po["order"] : null;
        if ($po["type"] != 0) {
            $mod = $po["code"] != 0 ? $couponhis->where("cou_disid=" . $po["code"])->select() : $couponhis->select();
            $where["ord_sn"] = array("in", implode(",", i_array_column($mod, "cou_orders")));
        }
        $this->assign("menulist", json_encode($chart["menu"]));
        unset($chart["menu"]);
        $print = $static->reportSerchData($order, $chart, $where);
        $this->assign("datalist", json_encode($print["nums"]));
        $this->assign("goldlist", json_encode($print["gold"]));
        $where["ord_addtime"] = array("between", array($chart[0]["ord_addtime"][1][0], $chart[count($chart) - 1]["ord_addtime"][1][1]));
        //
        $data = commpage($order, $where, "ord_addtime desc", 12);
        $this->assign("data", $data);
        $this->display();
    }

    /** 获取子目录 * */
    public function getSaleCode($code)
    {
        $disisbn = M("disisbn");
        if ($code != null) {
            $list = $disisbn->where("dis_custype=" . $code)->select();
            $this->ajaxReturn($list);
        } else {
            $this->ajaxReturn(null);
        }
    }
}
